#ifndef MONITORPRO_SPAN_H
#define MONITORPRO_SPAN_H

#include "tag.h"
#include "segment_reference.h"
#include "sys/time.h"

#include <string>
#include <vector>

enum class SkySpanType
{
    Entry,
    Exit,
    Local
};

enum class SkySpanLayer
{
    Unknown,
    Database,
    RPCFramework,
    Http,
    MQ,
    Cache
};

class Span
{
public:
    Span();
    ~Span();
    int getSpanId() const;
    int getParentSpanId() const;
    long getStartTime() const;
    long getEndTime() const;
    std::vector<SkySegmentReference *> getRefs();
    std::string getOperationName();
    std::string getPeer();
    SkySpanType getSpanType();
    SkySpanLayer getSpanLayer();
    int getComponentId() const;
    bool getIsError() const;
    std::vector<Tag *> getTags();
    bool getSkipAnalysis() const;
    void setStartTime(long ms);
    void setEndTime(long ms);
    void setEndTime();
    void setOperationName(const std::string &name);
    void setPeer(const std::string &peer);
    void setSpanType(SkySpanType type);
    void setSpanLayer(SkySpanLayer layer);
    void setComponentId(int id);
    void setIsError(bool error);
    void setSpanId(int id);
    void setParentSpanId(int id);
    void pushTag(Tag *tag);
    void addTag(const std::string &key, const std::string &value);
    void pushRefs(SkySegmentReference *ref);

private:
    static long getUnixTimeStamp();

private:
    int spanId;
    int parentSpanId;
    long startTime;
    long endTime;
    std::vector<SkySegmentReference *> refs;
    std::string operationName;
    std::string peer;
    SkySpanType spanType;
    SkySpanLayer spanLayer;
    int componentId;
    bool isError;
    std::vector<Tag *> tags;
    bool skipAnalysis;
};

#endif